package com.digital.welcome.controller;

import com.digital.welcome.annotation.OperationLog;
import com.digital.welcome.entity.SchoolInformation;
import com.digital.welcome.service.SchoolInformationService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 韩
 */
@RestController
@RequestMapping("/school-information")
public class SchoolInformationController {

    @Autowired
    private SchoolInformationService schoolInformationService;

    @ApiOperation("信息查询")
    @RequestMapping(value = "/select", method = RequestMethod.POST)
    public String selectSchoolInformation(@RequestBody SchoolInformation schoolInformation) throws InterruptedException {
        return schoolInformationService.selectSchoolInformation(schoolInformation.getTitle());
    }

    @OperationLog()
    @ApiOperation("新闻信息发布")
    @RequiresPermissions("notice")
    @RequestMapping(value = "/push", method = RequestMethod.POST)
    public String insertContent(@RequestBody SchoolInformation schoolInformation) {
        return schoolInformationService.insertInformation(schoolInformation);
    }


    @ApiOperation("首页新闻中心")
    @RequestMapping(value = "/select", method = RequestMethod.GET)
    public String getSchoolInformation() throws InterruptedException {
        return schoolInformationService.getAllSchoolInformation();
    }


    @ApiOperation("删除schoolInformation")
    @RequiresPermissions("notice")
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public String deleteSchoolInformation(@RequestBody SchoolInformation schoolInformation) {
        return schoolInformationService.deleteSchoolInformation(schoolInformation);
    }

    @RequiresPermissions("notice")
    @ApiOperation("修改文章")
    @RequestMapping(value = "/updateInformation", method = RequestMethod.POST)
    public String supdateInformation(@RequestBody SchoolInformation schoolInformation) {
        return schoolInformationService.updateInformation(schoolInformation);
    }


}
